package no.hio.wsclient.dao;

import junit.framework.TestCase;
import no.hio.wsproviderstock.StockItem;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * @author Henning
 *
 */
public class StockItemDAOWebServiceImplTestCase extends TestCase
{
	StockItemDAOWebServiceImpl stockDAO;
	StockItem stockItem3;

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception
	{
		stockDAO = new StockItemDAOWebServiceImpl();
		stockItem3 = new StockItem();
		stockItem3.setProductID(Integer.MAX_VALUE);
	}

	/**
	 * Test method for {@link no.hio.wsclient.dao.StockItemDAOWebServiceImpl#findAllStockItems()}.
	 */
	@Test
	public void testFindAllStockItems()
	{
		assertTrue("list length should be more than positiv", stockDAO.findAllStockItems().size() >= 0 );
	}

	/**
	 * Test method for {@link no.hio.wsclient.dao.StockItemDAOWebServiceImpl#findByProductID(int)}.
	 */
	@Test
	public void testFindByProductID()
	{
		stockItem3.setStockLocation("testStock");
		stockDAO.insertStockItem(stockItem3);
		assertEquals("testStock", stockDAO.findByProductID(stockItem3.getProductID()).getStockLocation());
	}

	/**
	 * Test method for {@link no.hio.wsclient.dao.StockItemDAOWebServiceImpl#insertStockItem(no.hio.wsproviderstock.StockItem)}.
	 */
	@Test
	public void testInsertStockItem()
	{
		int before = stockDAO.findAllStockItems().size();
		stockDAO.insertStockItem(stockItem3);
		
		assertEquals(before + 1, stockDAO.findAllStockItems().size());
	}

	/**
	 * Test method for {@link no.hio.wsclient.dao.StockItemDAOWebServiceImpl#removeStockItem(no.hio.wsproviderstock.StockItem)}.
	 */
	@Test
	public void testRemoveStockItem()
	{
		stockDAO.insertStockItem(stockItem3);
		int beforeLength = stockDAO.findAllStockItems().size(); 
		stockDAO.removeStockItem(stockItem3);
		
		assertEquals(beforeLength - 1, stockDAO.findAllStockItems().size());
	}

	/**
	 * Test method for {@link no.hio.wsclient.dao.StockItemDAOWebServiceImpl#updateStockItem(no.hio.wsproviderstock.StockItem)}.
	 */
	@Test
	public void testUpdateStockItem()
	{
		stockDAO.insertStockItem(stockItem3);
		stockItem3.setStockLocation("testStockLocation");
		stockDAO.updateStockItem(stockItem3);
		assertEquals("testStockLocation", stockDAO.findByProductID(stockItem3.getProductID()).getStockLocation());
	}
	
	@After
	public void tearDown() throws Exception {
		stockDAO.removeStockItem(stockItem3);
	}

}
